package com.pkk.log.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pkk.components.rpc.request.PagedQueryRequest;
import com.pkk.log.common.reqdto.LogPageReqData;
import com.pkk.log.entity.log.SysLogEntity;
import com.pkk.log.mybatis.log.SysLogMapper;
import com.pkk.log.service.SysLogService;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author kunzai
 * @since 2019-06-13
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLogEntity> implements SysLogService {

  /**
   * @Description: 分页查询日志
   * @Param: [request]
   * @return: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.pkk.log.entity.log.SysLogEntity>
   * @Author: peikunkun
   * @Date: 2019/7/14 0014 下午 4:11
   */
  @Override
  public Page<SysLogEntity> findLogInfoPage(PagedQueryRequest<LogPageReqData> request) {
    // 不进行 count sql 优化，解决 MP 无法自动优化 SQL 问题
    Page page = new Page<>(request.getPage().getPageIndex(), request.getPage().getPageSize());
    page.setOptimizeCountSql(false);
    Map condition = new HashMap<>();
    condition.put("method", request.getBody().getMethod());
    condition.put("args", request.getBody().getArgs());
    return baseMapper.findLogInfoPage(page, condition);
  }
}
